﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <qdebug.h>
#include "util.h"
#include "onnxdetector.h"
#include "opencv2/opencv.hpp"
#include "opencv2/dnn.hpp"
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include "iostream"
#include "dnndetector.h"
#include <filesystem>
#include <QTimer>
#include "loadingdialog.h"

namespace fs = std::filesystem;

QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    void on_btnLookFile_clicked();

    void on_btnDetect_clicked();

    void on_btnClassNames_clicked();

    void on_btnModel_clicked();

    void on_btnDnn_clicked();

    void on_action_camera_triggered(bool checked);

    void on_action_image_triggered(bool checked);

private:
    Ui::MainWindow *ui;
    std::string imagePath;//图片路径
    std::vector<uchar> imageBuffer; //图片
    std::string classNamesPath;
    std::vector<std::string> classNames;//加载类型文件，转换为标签字符串数组
    std::string modelPath;//模型地址
    std::unique_ptr<OnnxDetector> detector;

    cv::Mat originalImage;
    cv::Mat resultImage;
    const std::string detections_file = "detections.txt";

    cv::Mat frame;
    cv::VideoCapture capture;
    QTimer *camera_timer;
    cv::Mat exeDetect(cv::Mat image, QString source="image");


private:
    bool createDirectoryIfNotExists(const std::string& dirPath);
};
#endif // MAINWINDOW_H
